using System;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;

namespace AreaBuilder {
    [Serializable]
    public class Item {
        private ArrayList affects = new ArrayList();
        private ArrayList flags = new ArrayList();
        private ArrayList triggers = new ArrayList();

        [XmlAttribute(AttributeName = "vnum")]
        public int VNum { get; set; }

        [XmlElement(ElementName = "keywords")]
        public String Keywords { get; set; }

        [XmlElement(ElementName = "name")]
        public String Name { get; set; }

        [XmlElement(ElementName = "description")]
        public String Description { get; set; }

        [XmlElement(ElementName = "material")]
        public String Material { get; set; }

        [XmlElement(ElementName = "itemType")]
        public String ItemType { get; set; }

        [XmlElement(ElementName = "extraFlags")]
        public String ExtraFlags { get; set; }

        [XmlElement(ElementName = "wearFlags")]
        public String WearFlags { get; set; }

        [XmlElement(ElementName = "V0")]
        public String V0 { get; set; }

        [XmlElement(ElementName = "V1")]
        public String V1 { get; set; }

        [XmlElement(ElementName = "V2")]
        public String V2 { get; set; }

        [XmlElement(ElementName = "V3")]
        public String V3 { get; set; }

        [XmlElement(ElementName = "V4")]
        public String V4 { get; set; }

        [XmlElement(ElementName = "V5")]
        public String V5 { get; set; }

        [XmlElement(ElementName = "level")]
        public int Level { get; set; }

        [XmlElement(ElementName = "minSize")]
        public int MinSize { get; set; }

        [XmlElement(ElementName = "maxSize")]
        public int MaxSize { get; set; }

        [XmlElement(ElementName = "weight")]
        public int Weight { get; set; }

        [XmlElement(ElementName = "cost")]
        public int Cost { get; set; }

        [XmlElement(ElementName = "trapLevel")]
        public String TrapLevel { get; set; }

        [XmlElement(ElementName = "trapTrigger")]
        public String TrapTrigger { get; set; }

        [XmlElement(ElementName = "trapDamage")]
        public String TrapDamage { get; set; }

        [XmlElement(ElementName = "trapCharges")]
        public String TrapCharges { get; set; }

        [XmlElement(ElementName = "extraKeywords")]
        public String ExtraKeys { get; set; }

        [XmlElement(ElementName = "extraDescription")]
        public String ExtraDesc { get; set; }

        [XmlArray("affects")]
        [XmlArrayItem("affect", typeof (ItemAffect))]
        public ArrayList Affects {
            get { return affects; }
            set { affects = value; }
        }

        [XmlArray("triggers")]
        [XmlArrayItem("trigger", typeof (ItemTrigger))]
        public ArrayList Triggers {
            get { return triggers; }
            set { triggers = value; }
        }

        [XmlArray("flags")]
        [XmlArrayItem("flag", typeof (ItemFlag))]
        public ArrayList Flags {
            get { return flags; }
            set { flags = value; }
        }

        public void addAffect(ItemAffect aff) {
            affects.Add(aff);
        }

        public void addTrigger(ItemTrigger trig) {
            triggers.Add(trig);
        }

        public void addFlag(ItemFlag flag) {
            flags.Add(flag);
        }

        public Item Clone() {
            var ms = new MemoryStream();
            var bf = new BinaryFormatter();

            bf.Serialize(ms, this);

            ms.Seek(0, SeekOrigin.Begin);

            var i = bf.Deserialize(ms) as Item;
            ms.Close();

            return i;
        }
    }
}